#ifndef SPRITEINSTANCELIST_H_INCLUDED
#define SPRITEINSTANCELIST_H_INCLUDED

#include <iostream>
#include <list>

#include "Mutex_Wrapper.h"
#include "Image_Wrapper.h"
#include "Misc.h"
#include "SpriteInstance.h"
#include "CurrentContext.h"
#include "Viewport.h"
#include "Debug.h"

using namespace std;

class  SpriteInstanceList
{
    list<SpriteInstance> m_spriteInstances;
    Mutex_Wrapper m_mutex;
    uint m_spriteInstanceIndexCounter;
    CurrentContext &m_currentCtx;
    Viewport &m_viewport;

    public:
    SpriteInstanceList();
    bool add(uint imgId, uint spriteId, SDL_Rect rect, bool visible = true, bool solid = true);
    bool hasXY(int x, int y);
    void draw(SDL_Surface *layer);
    bool makeSpriteAtXYActive(int x, int y);
    void moveActiveSpritebyXY(Sint16 x, Sint16 y);
    bool activeSpriteBringToFront();
    bool activeSpriteSendToBack();
    bool activeSpriteToggleSolid();
    bool activeSpriteToggleVisible();
    bool activeSpriteDelete();
    virtual ~SpriteInstanceList();
    list<SpriteInstance> & getSpriteInstances();

    void lock();
    void unlock();
    void clear();

//    bool find(uint spriteId, uint &imgId, RectInfo &rect);
};

inline void SpriteInstanceList::clear()
{
    lock();
    m_spriteInstances.clear();
    m_spriteInstanceIndexCounter = 0;
    unlock();
}

inline list<SpriteInstance> & SpriteInstanceList::getSpriteInstances()
{
    return m_spriteInstances;
}

inline void SpriteInstanceList::lock() {
    m_mutex.lock();
}

inline void SpriteInstanceList::unlock() {
    m_mutex.unlock();
}

#endif // SPRITEINSTANCELIST_H_INCLUDED
